﻿/// <reference path="../jqGrid/jqGrid-4.6.0/jquery.jqGrid.src.js" />
/// <reference path="../jqGrid/jqGrid-4.6.0/i18n/grid.locale-en.js" />
/// <reference path="../jQuery/jquery-1.11.0.js" />
/// <reference path="../jQuery-UI/jquery-ui-1.10.4.custom.js" />
/// <reference path="../jQuery-UI/i18n/jquery.ui.datepicker-en-GB.js" />
/// <reference path="../qTip2/qTip2-2.2.0/jquery.qtip.js" />
/// <reference path="../vpGrid/vpGrid-1.1.6.js" />
/// <reference path="../vpGrid/i18n/vpGrid-1.1.6.locale-en.js" />



(function (window, $, vpGrid, undefined) {
    var MyCompany = window.MyCompany || {};
    MyCompany.MyGrid = MyCompany.MyGrid || {};
    var myGrid = MyCompany.MyGrid;
    try {
        
        onSummaryCellRenderingEventhandler = function(source, eventArgs){
            try {

            } catch (e) {
                vpGrid.logException(e);
            }
        }

        onDataReceivedEventhandler = function (source, eventArgs) {
            try {
                var data = eventArgs.data;
                var itemCount = data.length;
                for (var i = 0; i < itemCount; i++) {
                    var item = data[i];
                    if (item.style === "U") {
                        item.style = "Universal";
                        continue;
                    }
                    if (item.style === "W") {
                        item.style = "Women's";
                        continue;
                    }

                    if (item.style === "M") {
                        item.style = "Men's";
                        continue;
                    }


                }
                
            } catch (e) {
                vpGrid.logException(e);
            }
        }

        onCellUpdatedEventhandler = function (source, eventArgs) {
            try {

            } catch (e) {
                vpGrid.logException(e);
            }
        }

        onCellValidatingEventhandler = function (source, eventArgs) {
            try {
                
            } catch (e) {
                vpGrid.logException(e);
            }
        }

        onRowEditingEventhandler = function (source, eventArgs) {
            try {
                
            } catch (e) {
                vpGrid.logException(e);
            }
        };

        onCellEditingEventhandler = function (source, eventArgs) {
            try {
                
            } catch (e) {
                vpGrid.logException(e);
            }
        };

        onModalDialogOpeningEventhandler = function (source, eventArgs) {
            try {
                var dialogId = eventArgs.dialogId;
                var rowData = eventArgs.rowData;

                if (dialogId === "serverSideDialog1") {
                    var itemId = rowData.remoteId;
                    var url = eventArgs.iframeUrl;
                    url = url + "?ItemId=" + itemId + "&IsInFrame=true";
                    eventArgs.iframeUrl = url;
                    return;
                }

            } catch (e) {
                vpGrid.logException(e);
            }
        };

        vpGrid.registerEventHandler(vpGrid.Event.onSummaryCellRendering, onSummaryCellRenderingEventhandler);
        vpGrid.registerEventHandler(vpGrid.Event.onDataReceived, onDataReceivedEventhandler);
        vpGrid.registerEventHandler(vpGrid.Event.onCellUpdated, onCellUpdatedEventhandler);
        vpGrid.registerEventHandler(vpGrid.Event.onCellValidating, onCellValidatingEventhandler);
        vpGrid.registerEventHandler(vpGrid.Event.onRowEditing, onRowEditingEventhandler);
        vpGrid.registerEventHandler(vpGrid.Event.onCellEditing, onCellEditingEventhandler);
        vpGrid.registerEventHandler(vpGrid.Event.onModalDialogOpening, onModalDialogOpeningEventhandler);


        // Dom event Handlers
        myGrid.onSelectChangedEventHandler1 = function (source, eventArgs) {
            try {
                var selectedId = $(source.target).val();

                if (eventArgs === "kindOfProducts") {
                    
                    var url = "./StartTemplate.html?TypeOfProduct=" + selectedId
                    window.location.href = url;
                }

            } catch (e) {
                vpGrid.logException(e);
            }
        };


    } catch (e) {
        vpGrid.logException(e);
    }
    finally {
        window.MyCompany = MyCompany;
    }


})(this, jQuery, vpGrid);
